function InstaFeeder(){
	this.initialize=function(){
		$('#sendbutton').click(function(){
			loginhandler();
		});
	}
	
	function loginhandler(){
		var username=$('#username').val();
		var password=$('#password').val();
		var url="instapasscheck";
		var data={'username':username,'password':password};
		$.get(url,data,function(responsedata){
			responsedata=JSON.parse(responsedata);
			try{responsedata['result'];}
			catch(err){
			}
			if(responsedata['result']=='failed'){
				alert('login failed try again');
			}
			else{
				createList(responsedata)
			}
		});
	}
	
	function createList(responsedata){
		$('#registrationform').remove();
		$('#tablepositioner').remove();
		var title=$('<div class="greetings" >Thanks for logging in with Instapaper,<br /> Click on the icons to add the feed to Instapaper</div>')
		$('body').append(title)
		var feedscontainer=$('<div id="feedscontainer" />');
		$('body').append(feedscontainer);
		var tech=$('<div id="tech" />');
		var news=$('<div id="news" />');
		var custom=$('<div id="custom" />');
		$('#feedscontainer').append(tech);
		$('#feedscontainer').append(news);
		$('#feedscontainer').append(custom);
		var techheader=$('<div class="header">Tech News</div>');
		var newsheader=$('<div class="header">News</div>');
		var customheader=$('<div class="header">Your Feeds</div>');
		$(tech).append(techheader);
		$(news).append(newsheader);
		$(custom).append(customheader);
		for(key in responsedata){
			currentdata=responsedata[key]
			var feedsnamecontainer=$('<div class="feedsnamecontainer" />');
			var feeds=$('<div class="feeds" />');
			var image=$('<div class="image" id="'+currentdata['feedname']+'"><img src="'+currentdata['feedimage']+'" width="120" height="auto"></div>');
			$(feeds).append(image);
			var status=$('<div class="ifchecked"><img status="unchecked" id="'+currentdata['feedname']+'ifchecked'+'" src="../images/unchecked.jpg" width="20" height=auto></div>');
			$(feeds).append(status);
			$(feedsnamecontainer).append(feeds);
			var feedname=$('<div class="feedname">'+currentdata['feedname']+'</div>');
			$(feedsnamecontainer).append(feedname);
			if(currentdata['feedtype']=='tech'){
				$(tech).append(feedsnamecontainer);	
			}
			else if(currentdata['feedtype']=='news'){
				$(news).append(feedsnamecontainer);
			}
			else if(currentdata['feedtype']=='custom'){
				$(news).append(feedsnamecontainer);
			}
			
			$(image).click(function(){
				var id=$(this).attr('id')+'ifchecked';
				if($('#'+id).attr('status')=='unchecked'){
						$('#'+id).attr('src','/images/checked.png');
						$('#'+id).attr('status','checked');
				}
				else{
						$('#'+id).attr('src','/images/unchecked.jpg');
						$('#'+id).attr('status','unchecked')
				}
			});		
		}
	}
	
}
